/**************************************************************************
 *
 *        Copyright (c) 2007-2008 by Sunplus mMedia Inc., Ltd.
 *
 *  This software is copyrighted by and is the property of Sunplus
 *  mMedia Inc., Ltd. All rights are reserved by Sunplus mMedia
 *  Inc., Ltd. This software may only be used in accordance with the
 *  corresponding license agreement. Any unauthorized use, duplication,
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice MUST not be removed or modified without prior
 *  written consent of Sunplus mMedia Inc., Ltd.
 *
 *  Sunplus mMedia Inc., Ltd. reserves the right to modify this
 *  software without notice.
 *
 *  Sunplus mMedia Inc., Ltd.
 *  19-1, Innovation First Road, Science-Based Industrial Park,
 *  Hsin-Chu, Taiwan, R.O.C.
 *
 **************************************************************************/
/**
 * @file		front_api.h
 * @brief		front module header file.
 * @author		Matt Wang
 * @since		2008-09-08
 * @date		2009-01-09
 */
#ifndef __FRONT_API_H__
#define __FRONT_API_H__

#include "hal_front.h"

/**************************************************************************
 *                              C O N S T A N T S
 **************************************************************************/
#define FRONT_USE_MACRO  1  /* fdk internal usage only. */

#define FRONT_DEVICE_TOT  1

typedef enum {
	FRONT_PARA_MCLK_CFG,
	FRONT_PARA_PCLK_CFG,
	FRONT_PARA_SYNC_INVERT_ENABLE,
	FRONT_PARA_RESHAPE_ENABLE,
	FRONT_PARA_RESHAPE_REGION,
	FRONT_PARA_CROP_REGION,
	FRONT_PARA_FRONT_TO_CDSP_GATING_ENABLE,
	FRONT_PARA_TG_TOTAL_REGION,
	FRONT_PARA_TG_SYNC_GENERATOR_ENABLE,
	FRONT_PARA_YUV_OUTPUT_SEQUENCE_CFG,
	FRONT_PARA_YUV_CCIR_MODE,
	FRONT_PARA_YUV_SUB128_ENABLE,
	FRONT_PARA_YUV_INPUT_ENABLE,
	FRONT_PARA_MAX_ID,
} frontParaId_e;  /* plz keep sync to HAL_FrontParaId_e. */

typedef enum {
	FRONT_YUV_OUTPUT_UYVY = (0 << 0),
	FRONT_YUV_OUTPUT_YVYU = (1 << 0),
	FRONT_YUV_OUTPUT_VYUY = (2 << 0),
	FRONT_YUV_OUTPUT_YUYV = (3 << 0),
} frontYuvOutputSeqCfg_e;  /* plz keep sync to HAL_FrontYuvOutputSeqCfg_e. */

typedef enum {
	FRONT_YUV_CCIR601 = (0 << 4),
	FRONT_YUV_CCIR656 = (1 << 4),
} frontYuvCcirMode_e;  /* plz keep sync to HAL_FrontYuvCcirMode_e. */

typedef enum {
	FRONT_MCLK_SRC_INT = (0 << 2),
	FRONT_MCLK_SRC_EXT = (1 << 2),
} frontMclkSrc_e;  /* plz keep sync to HAL_FrontMclkSrc_e. */

#if 1  /* use define instead of enum to reduce compile warning. */
#define FRONT_PCLK_SRC_INT  (0 << 3)
#define FRONT_PCLK_SRC_EXT  (1 << 3)
#else
typedef enum {
	FRONT_PCLK_SRC_INT = (0 << 3),
	FRONT_PCLK_SRC_EXT = (1 << 3),
} frontpclkSrc_e;  /* plz keep sync to HAL_FrontpclkSrc_e. */
#endif

typedef enum {
	FRONT_WAIT_HSYNC  = (1 << 0),
	FRONT_WAIT_VSYNC  = (1 << 1),
	FRONT_WAIT_HVALID = (1 << 2),
	FRONT_WAIT_VVALID = (1 << 3),
} frontWaitSource_e;  /* plz keep sync to HAL_FrontWaitSource_e. */

typedef enum {
	FRONT_WAIT_FALLING = 0,
	FRONT_WAIT_RISING  = 1,
	FRONT_WAIT_HIGH    = 2,
	FRONT_WAIT_LOW     = 3,
} frontWaitMode_e;  /* plz keep sync to HAL_FrontWaitMode_e. */

typedef enum {
	FRONT_FRAME_RATE_30   = 0,
	FRONT_FRAME_RATE_25   = 1,
	FRONT_FRAME_RATE_15   = 0,
	FRONT_FRAME_RATE_12P5 = 1,
} frontFrameRate_e;

typedef enum {
	FRONT_DEV_INFO_DATA_FMT,
	FRONT_DEV_INFO_TOT,
} frontDeviceInfo_e;

typedef enum {
	FRONT_DATA_FMT_RAW,
	FRONT_DATA_FMT_YUV,
	FRONT_DATA_FMT_TOT,
} frontDataFmt_e;

typedef enum {
	FRONT_EXT_OP_AE_TARGET_LUMINANCE_SET,
	FRONT_EXT_OP_AE_EXPOSURE_COMPENSATION_SET,
	FRONT_EXT_OP_AE_FRAME_RATE_SET,
	FRONT_EXT_OP_AWB_MODE_SET,
	FRONT_EXT_OP_AFTER_SNAP_SHOT,
	FRONT_EXT_OP_TOT,
} frontExtendOperatingFunc_e;

typedef enum {
	SENSOR_SNAP_FLASH_CFG_MODE = 0,
	SENSOR_SNAP_FLASH_CFG_WIDTH = 1,
	SENSOR_SNAP_FLASH_CFG_H_POS = 2,
	SENSOR_SNAP_FLASH_CFG_DELAY_TYPE = 3,
} sensor_snap_flash_cfg_t;

typedef enum {
	SENSOR_SNAP_FLASH_MODE_OFF = 0,
	SENSOR_SNAP_FLASH_CURTAIN_FRONT_SYNC = 0x02,
	SENSOR_SNAP_FLASH_CURTAIN_REAR_SYNC = 0x82,
} sensor_snap_flash_mode_t;

typedef enum {
	SENSOR_FLASH_DELAY_TYPE_H_POS = 0,
	SENSOR_FLASH_DELAY_TYPE_IMMEDIATE_TIMER = 2,
	SENSOR_FLASH_DELAY_TYPE_TOTAL,
} sensor_flash_delay_t;

typedef enum {
	SENSOR_PREFLASH_CFG_WIDTH = 1,
	SENSOR_PREFLASH_CFG_H_POS = 2,
	SENSOR_PREFLASH_CFG_DELAY_TYPE = 3,
} sensor_preflash_cfg_t;

/**************************************************************************
 *                              D A T A   T Y P E S
 **************************************************************************/
typedef struct {
	UINT16 ev;
	UINT32 shutter;
	UINT16 gain;
	UINT16 iris;
} frontAe_t;

typedef struct {
	UINT16 width;
	UINT16 height;
	UINT16 xoff;
	UINT16 yoff;
	UINT16 lineTot;
	UINT16 frameTot;
	UINT16 mclkDiv;
	UINT8  mclkPhase;
	UINT16 pclkDiv;
	UINT8  pclkPhase;
	UINT32 pclkFreq;
	UINT8  reshapeHen;
	UINT16 reshapeHfall;
	UINT16 reshapeHrise;
	UINT8  reshapeVen;
	UINT16 reshapeVfall;
	UINT16 reshapeVrise;
	UINT16 lcXmoff;
	UINT8  lcXminc;
	UINT16 lcYmoff;
	UINT8  lcYminc;
	UINT8  lcStepFact1;
	UINT8  lcStepFact2;
	UINT8  lcPathMode;
	UINT8  lcRgbCh;
	frontAe_t *ae60hzTbl;
	frontAe_t *ae50hzTbl;
	UINT8  *aeMaxIdxTbl;
	UINT8  *aeMinIdxTbl;
	UINT8  ev10ExpIdx;
	UINT16 *gainTbl;
	UINT8  gainMaxIdx;
	UINT8  gainMinIdx;
} frontPrevCapabDesc_t;

typedef struct {
	UINT16 width;
	UINT16 height;
	UINT16 xoff;
	UINT16 yoff;
	UINT16 lineTot;
	UINT16 frameTot;
	UINT16 mclkDiv;
	UINT8  mclkPhase;
	UINT16 pclkDiv;
	UINT8  pclkPhase;
	UINT32 pclkFreq;
	UINT8  reshapeHen;
	UINT16 reshapeHfall;
	UINT16 reshapeHrise;
	UINT8  reshapeVen;
	UINT16 reshapeVfall;
	UINT16 reshapeVrise;
	UINT16 lcCenterX;
	UINT16 lcCenterY;
	UINT16 lcXmoff;
	UINT8  lcXminc;
	UINT16 lcYmoff;
	UINT8  lcYminc;
	UINT8  lcStepFact1;
	UINT8  lcStepFact2;
	UINT8  lcPathMode;
	UINT8  lcRgbCh;
} frontSnapCapabDesc_t;

/* this data type is because of keil c function pointer argument limitation. */
typedef struct {
	frontPrevCapabDesc_t **ppprevCap;
	frontSnapCapabDesc_t **ppsnapCap;
} frontCapabilityArg_t;

/* this data type is because of keil c function pointer argument limitation. */
typedef struct {
	UINT32 val;
	UINT8 isr;
	UINT8 upd;
} frontExposureTimeArg_t;

/* operating function. */
typedef UINT8 *(code *pfOperatingFrontDevNameGet_t)(void);
typedef void (code *pfOperatingFrontFrameRateSet_t)(UINT8 fps);
typedef void (code *pfOperatingFrontCapabilityGet_t)(frontCapabilityArg_t *parg);
typedef void (code *pfOperatingFrontPowerOn_t)(void);
typedef void (code *pfOperatingFrontPowerOff_t)(void);
typedef void (code *pfOperatingFrontPreviewModeSet_t)(void);
typedef void (code *pfOperatingFrontSnapModeSet_t)(void);
typedef void (code *pfOperatingFrontSnapShot_t)(UINT8 first);
typedef void (code *pfOperatingFrontGainSet_t)(UINT8 val, UINT8 isr, UINT8 upd);
typedef void (code *pfOperatingFrontExposureTimeSet_t)(frontExposureTimeArg_t *parg);
typedef UINT8 (code *pfOperatingFrontOpticalBlackStatusGet_t)(void);
typedef UINT8 (code *pfOperatingFrontOpticalBlackCalibrate_t)(void);
typedef void (code *pfOperatingFrontShutterOpen_t)(void);
typedef void (code *pfOperatingFrontShutterClose_t)(void);

typedef struct {
	UINT8 expGainSetPos;
	UINT8 gainAfterExp;
	pfOperatingFrontDevNameGet_t pfOpDevNameGet;
	pfOperatingFrontFrameRateSet_t pfOpFrameRateSet;
	pfOperatingFrontCapabilityGet_t pfOpCapabilityGet;
	pfOperatingFrontPowerOn_t pfOpPowerOn;
	pfOperatingFrontPowerOff_t pfOpPowerOff;
	pfOperatingFrontPreviewModeSet_t pfOpPreviewModeSet;
	pfOperatingFrontSnapModeSet_t pfOpSnapModeSet;
	pfOperatingFrontSnapShot_t pfOpSnapShot;
	pfOperatingFrontGainSet_t pfOpGainSet;
	pfOperatingFrontExposureTimeSet_t pfOpExposureTimeSet;
	pfOperatingFrontOpticalBlackStatusGet_t pfOpOpticalBlackStatusGet;
	pfOperatingFrontOpticalBlackCalibrate_t pfOpOpticalBlackCalibrate;
	pfOperatingFrontShutterOpen_t pfOpShutterOpen;
	pfOperatingFrontShutterClose_t pfOpShutterClose;
} frontOperatingFunc_t;

/* extended operating function. */
typedef void (code *pfFrontExtOperatingFunc_t)(void *parg);

/**************************************************************************
 *                  F U N C T I O N   D E C L A R A T I O N S
 **************************************************************************/
/* front_logi.c */
UINT8 frontDevOpen(frontOperatingFunc_t *popFunc, UINT16 opFuncSize);
UINT8 frontExtendOpFuncSet(UINT8 id, UINT8 opId, pfFrontExtOperatingFunc_t pfExtOp);
UINT8 frontDevActSet(UINT8 id);
UINT8 frontDevActGet(void);
UINT8 frontFrameRateSet(UINT8 id, UINT8 fps);
UINT8 frontCapabilityGet(UINT8 id, frontPrevCapabDesc_t **ppprevCap, frontSnapCapabDesc_t **ppsnapCap);
UINT8 frontDeviceInfoGet(UINT8 id, UINT8 infId, UINT16 *ppara1, UINT16 *ppara2);
UINT8 frontPowerOn(UINT8 id);
UINT8 frontPowerOff(UINT8 id);
UINT8 frontPreviewModeSet(UINT8 id);
UINT8 frontSnapModeSet(UINT8 id);
UINT8 frontSnapShot(UINT8 id, UINT8 burst, UINT8 first);
UINT8 frontGainSet(UINT8 id, UINT8 val, UINT8 isr, UINT8 upd);
UINT8 frontExposureTimeSet(UINT8 id, UINT32 val, UINT8 isr, UINT8 upd);
UINT8 frontOpticalBlackStatusGet(UINT8 id);
UINT8 frontOpticalBlackCalibrate(UINT8 id);
UINT8 frontShutterOpen(UINT8 id);
UINT8 frontShutterClose(UINT8 id);
UINT8 frontLensCompensationSet(UINT8 id, UINT8 mode);
UINT8 frontPreviewSizeGet(UINT8 id, UINT16 *pwidth, UINT16 *pheight);
UINT8 frontSnapSizeGet(UINT8 id, UINT16 *pwidth, UINT16 *pheight);
UINT8 frontAeTargetLuminanceSet(UINT8 id, UINT8 val);
UINT8 frontAeExposureCompensationSet(UINT8 id, UINT8 val);
UINT8 frontAeFrameRateSet(UINT8 id, UINT16 val);
UINT8 frontAwbModeSet(UINT8 id, UINT8 mode);

#if FRONT_USE_MACRO
#define frontParaSet     HAL_FrontParaSet
#define frontReset       HAL_FrontReset
#define frontSignalWait  HAL_FrontSignalWait
#else
/* front_para.c */
UINT8 frontParaSet(UINT8 id, SINT16 para1, SINT16 para2, SINT16 para3, SINT16 para4, UINT8 upd);

/* front_reset.c */
void frontReset(void);

/* front_wait.c */
UINT8 frontSignalWait(UINT8 src, UINT8 mode, UINT8 num);
#endif

#endif  /* __FRONT_API_H__ */

